package com.acwing.partition19;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/1/30 16:54
 */
public class AC1801蹄子剪刀布 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(reader.readLine());
        int a = 0, b = 0;
        while (n-- > 0) {
            String[] ss = reader.readLine().split(" ");
            int x = Integer.parseInt(ss[0]), y = Integer.parseInt(ss[1]);
            x--;
            y--;
            //石头剪刀布，前面的总能赢后面的
            if ((x + 1) % 3 == y) a++;
            if ((y + 1) % 3 == x) b++;
        }
        writer.write(Math.max(a, b) + "\n");
        writer.flush();
    }
}
